home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / satellit / pgdir / pgdir.c < prev    next >
C/C++ Source or Header  |  1991-02-21  |  2KB  |  79 lines

  1. /**************************************************************************/
  2. /*  pgdir.c        Simple Display Utility for the Directory Files         */
  3. /*                 PG.DIR and PGARCH.DIR of an Microsat.                  */
  4. /*  21Feb91                                         by Peter Gülzow DB2OS */
  5. /**************************************************************************/
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <time.h>
  9. #include "pgdir.h"
  10.  
  11. /* Globals */
  12. char time_stamp[12];
  13.  
  14. /* Functions */
  15. char *ptime(time_t);
  16.  
  17. /**************************************************************************/
  18. /**  main  ****************************************************************/
  19. /**************************************************************************/
  20. main(int argc, char * argv[])
  21. {
  22.   struct SHORT_DIR dir;
  23.   FILE *fp;
  24.   int  i;
  25.  
  26.   if (argc < 2)
  27.   {
  28.     printf("usage: pgdir <filename.dir>\n");
  29.     exit(-1);
  30.   }
  31.     
  32.   if ( (fp=fopen(argv[1], "rb")) == NULL)
  33.   {
  34.     printf("File <%s> does not exist.\n",argv[1]);
  35.     exit(-2);
  36.   }
  37.  
  38.   printf("\n** Directory of '%s' **\n\n",argv[1]);
  39.   puts("  File   From     To       Date  Time    Size            Title");
  40.   puts("-------------------------------------------------------------------------------");
  41.  
  42.   i=0;
  43.  
  44.   while (!feof(fp))
  45.   {
  46.     if (fread(&dir, sizeof(struct SHORT_DIR), 1, fp))
  47.     {
  48.       printf("%8lx %-8.8s %-8.8s %-11.11s %6ld %-.33s\n",
  49.           dir.fnumber,
  50.           dir.source,
  51.           dir.dest,
  52.           ptime(dir.ultime),
  53.           dir.fsize,
  54.           dir.title
  55.         );
  56.       i++;
  57.     }
  58.   }
  59.   printf("\n  %d entries listed.\n",i);
  60.   fclose(fp);
  61.   return;
  62. }
  63.  
  64. /*------------------------------------------------------------------------*/
  65. /*  ptime()        Print Time     gives a short timestamp  dd/mm hh:mm    */
  66. /*------------------------------------------------------------------------*/
  67. char *ptime(time_t utc)
  68. {
  69.   struct tm *pt;
  70.  
  71.   pt = gmtime(&utc);
  72.   sprintf(time_stamp, "%02d/%02d %02d:%02d",
  73.         pt->tm_mday, pt->tm_mon+1,
  74.         pt->tm_hour, pt->tm_min
  75.      );
  76.  
  77.   return time_stamp;
  78. }
  79.